package org.breathe.dynamic.thread.pool.core.convert;

import org.breathe.dynamic.thread.pool.core.thread.BreatheDtpExecutor;
import org.breathe.thread.pool.common.entity.BreatheDtpMainProperties;

import java.util.concurrent.TimeUnit;

/**
 * 线程池转换器
 * @author: breathe
 * @createTime: 2025-04-09
 */
public class ExecutorConvert {
    private ExecutorConvert() {}

    /**
     * 通过动态线程池抽取其中的配置
     * @param breatheDtpExecutor 动态线程池
     * @return 动态线程池主要配置
     */
    public static BreatheDtpMainProperties convert(BreatheDtpExecutor breatheDtpExecutor) {
        BreatheDtpMainProperties wrapper = new BreatheDtpMainProperties();
        wrapper.setDtpName(breatheDtpExecutor.getThreadPoolName());
        wrapper.setCorePoolSize(breatheDtpExecutor.getCorePoolSize());
        wrapper.setMaxPoolSize(breatheDtpExecutor.getMaximumPoolSize());
        wrapper.setKeepAliveTime(breatheDtpExecutor.getKeepAliveTime(TimeUnit.SECONDS));
        wrapper.setQueueCapacity(breatheDtpExecutor.getQueueCapacity());
        wrapper.setQueueType(breatheDtpExecutor.getQueueName());
        wrapper.setRejectType(breatheDtpExecutor.getRejectHandlerName());
        wrapper.setAllowCoreThreadTimeOut(breatheDtpExecutor.allowsCoreThreadTimeOut());
        return wrapper;
    }
}
